<?php
namespace app\branch\controller;

use think\Controller;
use think\Session;
use think\Request;

/**
 * 分公司房车管理
 */
class Caravancontrol extends Controller
{   
    use \app\common\traits\controller\TraitController;
    //登陆与权限判断
    protected $beforeActionList = [
        'checkLogin',
    ];
    protected function checkLogin()
    {
        if (!model('Managers')->checkLogin()) {
            $this->redirect('@manager/login');
            exit;
        }
    }
    //获取子级信息
    // public function getsoninfo($id)
    // {
    //   //['id' => $v['id'] , 'name' => $v['name']]
    //   $result=model("Areas")->where('pid',$id)->select()->toArray();
    //   foreach ($result as $k=> $v) {
    //     $ids[]=['id' => $v['id'] , 'name' => $v['name']];
    //   }
    //   return $ids;
    // }
    /**
     * [getList 房车管理列表]
     * @return [type] [description]
     */
    public function getList()
    {
      //去本公司下的营地
      $lo_bran_id = model('Managers')->getLoginUserInfo('branch_id');
      $campinfos = model('Campcontrols')->where('branch_id',$lo_bran_id)->select();
      $this->assign('campinfos',$campinfos);
      //取本公司下的所有房车
      $list = model('Caravancontrols')->getCaravanList(array_merge(input('get.'),['branch_id'=>$lo_bran_id]));
      return view('caravancontrol/list',['list'=>$list]);
    }
     /**
     * [getReadInfo 查看房车信息]
     * @param  [type] $id [description]
     * @return [type]     [description]
     */
    public function getReadInfo($id)
    {
        //房车详细信息
        $info = model("Caravancontrols")->getCaravanIofo($id);
        $ziduan1 = model('Caravancontrols')->getZiduan1();
        if ($info->status) {
          //房车日历
          $share = model('common/Caravans')->getCaravanStatus($id);
          $this->assign('share',$share['shares']);//获取日历表房车的分享状态
          $this->assign('trusts',$share['trusts']);//获取日历表房车的出租状态
          //$this->assign('disables',$share['disables']);//获取日历表房车的订单状态
          $this->assign('sharedisables',$share['disables']['shares']);//获取日历表房车分享订单状态
          $this->assign('trustdisables',$share['disables']['trusts']);//获取日历表房车托管订单状态
          $this->assign('notrustorderdisables',$share['disables']['trustsnoorder']);//获取日历表房车无订单托管订单状态
          $rentPrice = model('Calendar')->where('caravan_id',$id)->where('trusts','1')->column('single_day_price', 'datetimes');
          $this->assign('rentPrice',json_encode($rentPrice));
        }
       
        return view('caravancontrol/caravaninfo',['info'=>$info,'ziduan1'=>$ziduan1]);
    }
}
